package birdsong.comm;

import java.io.Serializable;

/**
 * Messages sent from the server to clients. A message contains a type (enum), a payload (String), 
 * and a sender (String). 
 * <p>
 * <b>Important:</b> <br>
 * A <i>message</i> refers to an object sent from the server to a client.<br>
 * A <i>Birdsong message</i> refers to an object sent from a client to his or her followers<br>
 * 
 * <p>
 * When a Birdsong message is being sent from one user to followers, the sender
 * is the nickname of the client. For all other messages the sender's nickname should be {@link #SERVER}. 
 * <p>
 * The payload varies depending on the message type.
 * 
 * @author While True
 * @version 1 
 */

public class ClientMessage implements ClientSideMessage, Serializable{
	
	private static final long serialVersionUID = 1L;
	private final Type messageType;
	private final String payload;
	private final String sender;

	/**
	 * Default Constructor.
	 * 
	 * @param messageType 		The type of the message.
	 * @param payload			The payload of the message.
	 * @param sender			The sender of the message.
	 */
	public ClientMessage(Type messageType, String payload, String sender){
		this.messageType = messageType;
		this.payload = payload;
		this.sender = sender;
	}
	
	/** Getter that returns the type of the message.
	 * 
	 * @return Returns the message type.
	 */
	@Override
	public Type getType() {
		 return messageType; 
	}

	/** Getter that returns the payload.
	 * 
	 * @return Returns the message payload.
	 */
	@Override
	public String getPayload() {
		return payload;
	}
	
	/** Getter that returns the senders nickname.
	 * 
	 * @return Returns the message sender nickname.
	 */
	@Override
	public String getSendersNickname() {
		return sender;
	}
	
}